<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            width:80px;
            height: 200px;
            margin-left: 50px;
            font-size: 30px;
            color: black;
            overflow-y: scroll;
        }
    
    
    </style>
</head>
<body>
    <style contenteditable style="display: block">
        .edit{
            width: 100px;
            font-size: 18px;
        }
    </style>
    <div class="box">
        <div class="item">你好</div>
        <div class="item">你好</div>
        <div class="item">你好</div>
        <div class="item">你好</div>
        <div class="item">你好</div>
        <div class="item">你好</div>
        <div class="item">你好</div>
        <div class="item">你好</div>
        <div class="item">你好</div>
        <div class="item">你好</div>
    </div>
    <div class="edit" contenteditable>可编辑</div>
    <script>
        var box  = document.querySelector('.box');
        //box.scrollTo(0,box.scrollHeight - box.clientHeight)
        box.onscroll = function(){
            console.log(this.scrollTop) //滚动距离顶部的距离 200
            console.log(this.scrollHeight) //滚动区域总高度  400
            console.log(this.clientHeight) //滚动条高度     200
        }
        setTimeout(function(){
            var item = document.querySelector('.item')
            var newItem=document.createElement("div")
            var textnode=document.createTextNode("一个")
            newItem.className = "item"
            var eleheight = item.clientHeight;
            newItem.appendChild(textnode)
            box.insertBefore(newItem,item)
            box.scrollTo(0,eleheight)
        },3000)
    </script>
</body>
</html>